package com.haoxuewa.controller;

import com.haoxuewa.service.EssayService;
import com.haoxuewa.service.EssayTempService;
import com.haoxuewa.service.MessageService;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/backstage")
public class MessageController {

    private final MessageService messageService;

    @Autowired
    public MessageController(MessageService messageService) {
        this.messageService = messageService;
    }

    @GetMapping("/getAuditMessageList")
    public String getAuditMessageList() {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("messageList", messageService.getAuditMessage());
        return jsonObject.toString();
    }

    @PostMapping("/messagePass")
    public String messagePass(@RequestBody Map<String, String> map) {
        int id = Integer.parseInt(map.get("id"));
        JSONObject jsonObject = new JSONObject();
        if (messageService.messagePass(id)) {
            jsonObject.put("code", "200");
        } else {
            jsonObject.put("code", "403");
        }
        return jsonObject.toString();
    }

    @PostMapping("/messageUnPass")
    public String messageUnPass(@RequestBody Map<String, String> map) {
        int id = Integer.parseInt(map.get("id"));
        JSONObject jsonObject = new JSONObject();
        if (messageService.messageUnPass(id)) {
            jsonObject.put("code", "200");
        } else {
            jsonObject.put("code", "403");
        }
        return jsonObject.toString();
    }
}
